<template>
  <div>
    <el-form :model="rewardForm" :rules="rewardFormRoles" ref="rewardForm" label-width="10em">
      <h-box header="红包及减免力度内容（全部必填，保存后不可修改，请谨慎核对后保存）">
        <el-form-item label="红包类型" prop="luckyType">
          <el-radio-group @change="onChangeLuckyType" v-model="rewardForm.luckyType" :disabled="type === 'edit'">
            <el-radio label="STATIC">固定金额</el-radio>
            <el-radio label="RANDOM">限定范围随机</el-radio>
            <el-radio label="ENUM">限定金额随机</el-radio>
          </el-radio-group>
        </el-form-item>

        <!-- 固定面额红包填写，start -->
        <template v-if="rewardForm.luckyType === 'STATIC'">
          <el-form-item label="红包金额" prop="_reduceCost">
            <el-input @change="onChangeReduceCost" v-model.number="rewardForm._reduceCost" :disabled="type === 'edit'" placeholder="请输入" style="width: 240px;">
              <template slot="prepend">立减</template>
              <template slot="append">元</template>
            </el-input>
            <div class="hui-color-text-secondary hui-font-size-small">红包优惠最少 0.01 元，2 位小数以内</div>
          </el-form-item>
          <el-form-item label="红包个数" prop="quantity">
            <el-input v-model.number="rewardForm.quantity" :disabled="type === 'edit'" placeholder="请输入" style="width: 240px;">
              <template slot="prepend">共</template>
              <template slot="append">个</template>
            </el-input>
            <div class="hui-color-text-secondary hui-font-size-small">最多 999999 个</div>
          </el-form-item>
        </template>
        <!-- 固定面额红包填写，end -->

        <!-- 随机面额红包填写，start -->
        <template v-else-if="rewardForm.luckyType === 'RANDOM'">
          <el-form-item label="随机金额范围" required>
            <el-form-item prop="_reduceCostMin" style="display: inline-block;">
              <el-input @change="onChangeReduceCostMin" v-model.number="rewardForm._reduceCostMin" :disabled="type === 'edit'" placeholder="请输入" style="width: 240px;">
                <template slot="prepend">最小</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <span class="hui-mx-8px">，</span>
            <el-form-item prop="_reduceCostMax" style="display: inline-block;">
              <el-input @change="onChangeReduceCostMax" v-model.number="rewardForm._reduceCostMax" :disabled="type === 'edit'" placeholder="请输入" style="width: 240px;">
                <template slot="prepend">最大</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <div class="hui-color-text-secondary hui-font-size-small">随机面额将在最小和最大值之间随机一个面额发给消费者，跟微信拼手气红包类似</div>
          </el-form-item>
          <el-form-item label="红包总金额" prop="_reduceCostTotal">
            <el-input @change="onChangeReduceCostTotal" v-model.number="rewardForm._reduceCostTotal" :disabled="type === 'edit'" placeholder="请输入" style="width: 240px;">
              <template slot="prepend">最多</template>
              <template slot="append">元</template>
            </el-input>
            <div class="hui-color-text-secondary hui-font-size-small">红包总金额发光后，会显示“来晚了，红包已经被抢光”</div>
          </el-form-item>
        </template>
        <!-- 随机面额红包填写，end -->

        <!-- 枚举面额红包填写，start -->
        <template v-else-if="rewardForm.luckyType === 'ENUM'">
          <el-form-item label="随机红包金额" prop="reduceEnum">
            <el-table :data="rewardForm.reduceEnum" stripe border size="medium" style="width: 400px; line-height: 23px;">
              <el-table-column label="红包金额">
                <template slot-scope="scope">{{ scope.row.reduceCost / 100 | currency('', 2) }} 元</template>
              </el-table-column>
              <el-table-column label="起用金额">
                <template slot-scope="scope">
                  <template v-if="scope.row.leastCost === 0">无门槛</template>
                  <template v-else>满 {{ scope.row.leastCost / 100 | currency('', 2) }} 元可用</template>
                </template>
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button @click="handleDeleteEnum(scope.$index, scope.row)" type="danger" size="mini" plain>删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-button @click="handleVisibleEnum" type="primary" size="mini" plain icon="el-icon-plus" class="hui-mt-1">增加红包种类</el-button>
          </el-form-item>
          <el-form-item label="红包个数" prop="quantity">
            <el-input v-model.number="rewardForm.quantity" :disabled="type === 'edit'" placeholder="请输入" style="width: 240px;">
              <template slot="prepend">共</template>
              <template slot="append">个</template>
            </el-input>
          </el-form-item>
        </template>
        <!-- 枚举红包面额填写，end -->

        <!-- 固定和随机面额填写的起用金额，start -->
        <el-form-item label="红包起用金额" prop="_leastCost" v-if="rewardForm.luckyType !== 'ENUM'">
          <el-input @change="onChangeLeastCost" v-model.number="rewardForm._leastCost" :disabled="type === 'edit'" placeholder="请输入" style="width: 240px;">
            <template slot="prepend">满</template>
            <template slot="append">元可用</template>
          </el-input>
          <div class="hui-color-text-secondary hui-font-size-small">起用金额填写 0 元即无门槛，限填写整数金额</div>
        </el-form-item>
        <!-- 固定和随机面额填写的起用金额，end -->
      </h-box>
      <h-box header="红包基础信息（全部必填，保存后不可修改，请谨慎核对后保存）">
        <el-form-item label="红包标题" prop="title">
          <el-input v-model="rewardForm.title" :disabled="type === 'edit'" :max-length="9" placeholder="最多 9 个字" style="width: 400px;"></el-input>
          <div class="hui-color-text-secondary hui-font-size-small">红包标题仅供管理员备注记录</div>
        </el-form-item>
        <el-form-item label="有效期类型" prop="dateInfoType">
          <el-radio-group @change="onChangeDateInfoType" v-model="rewardForm.dateInfoType" :disabled="type === 'edit'">
            <el-radio label="DATE_TYPE_FIX_TIME_RANGE">固定日期</el-radio>
            <el-radio label="DATE_TYPE_FIX_TERM">固定时长(自领取后按天算)</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="有效期" prop="_timeRange" v-if="rewardForm.dateInfoType === 'DATE_TYPE_FIX_TIME_RANGE'">
          <h-date-range :value.sync="rewardForm._timeRange" :start-time.sync="rewardForm.beginTimeStamp" :end-time.sync="rewardForm.endTimeStamp" :disabled="type === 'edit'" style="width: 400px;"></h-date-range>
        </el-form-item>
        <el-form-item label="有效期" required v-else-if="rewardForm.dateInfoType === 'DATE_TYPE_FIX_TERM'">
          <el-form-item prop="fixedTerm" style="display: inline-block;">
            <el-input v-model.number="rewardForm.fixedTerm" :disabled="type === 'edit'" style="width: 210px;">
              <template slot="prepend">有效期</template>
              <template slot="append">天</template>
            </el-input>
          </el-form-item>
          <span class="hui-mx-8px">，</span>
          <el-form-item prop="fixedBeginTerm" style="display: inline-block;">
            <el-input v-model.number="rewardForm.fixedBeginTerm" :disabled="type === 'edit'" style="width: 240px;">
              <template slot="prepend">领取后</template>
              <template slot="append">天生效</template>
            </el-input>
          </el-form-item>
        </el-form-item>
        <el-form-item label="统一过期时间" prop="_endTimeStamp" v-if="rewardForm.dateInfoType === 'DATE_TYPE_FIX_TERM'">
          <el-date-picker @change="onChangeEndTimeStamp" v-model="rewardForm._endTimeStamp" :disabled="type === 'edit'" :picker-options="pickerOptions" type="date" placeholder="请选择统一过期时间" value-format="timestamp" align="center"></el-date-picker>
          <div class="hui-color-text-secondary hui-font-size-small">固定时长优惠券，超过此日期后，优惠券统一过期</div>
        </el-form-item>
      </h-box>
      <h-box header="红包使用信息（保存后可修改）">
        <el-form-item label="可使用日期限制" prop="useAllWeekly">
          <el-radio-group v-model="rewardForm.useAllWeekly" @change="onChangeCanUseWeekly">
            <el-radio :label="true">所有日期</el-radio>
            <el-radio :label="false">一周内的某些天</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="可使用日期" prop="canUseWeekly" v-if="!rewardForm.useAllWeekly">
          <h-checkbox-weekly :value.sync="rewardForm.canUseWeekly"></h-checkbox-weekly>
          <div class="hui-color-text-secondary hui-font-size-small">示例：您可设置仅限 周一 至 周五 可用。如想每天都可用，全选即可</div>
        </el-form-item>
        <el-form-item label="可使用时段限制" prop="useAllDaily">
          <el-radio-group v-model="rewardForm.useAllDaily" @change="onChangeCanUseDaily">
            <el-radio :label="true">所有时段</el-radio>
            <el-radio :label="false">一天内的某些时段</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="可适用时段" prop="canUseDaily" v-if="!rewardForm.useAllDaily">
          <h-select-daily :value.sync="rewardForm.canUseDaily" style="width: 400px;"></h-select-daily>
          <div class="hui-color-text-secondary hui-font-size-small">示例：您可设置仅限一天内的部分时段可用，如可可用时段选择11点 - 12点，可用范围为 <b>大于等于 11:00</b>，<b>小于 12:00</b></div>
        </el-form-item>
        <el-form-item label="订单限制" prop="originalFeeOnly">
          <el-radio-group v-model="rewardForm.originalFeeOnly">
            <el-radio :label="false">所有订单</el-radio>
            <el-radio :label="true">仅限原价订单可用</el-radio>
          </el-radio-group>
          <ol class="hui-color-text-secondary hui-font-size-small hui-pl-1" style="line-height: 1.5;">
            <li>红包的促销计算优先级低于“消费满减 / 满折”，如您设置了所有订单均可使用本红包，则会 <b>先计算“消费满减 / 满折”促销</b>，折后金额满足红包起用金额，则本红包可以使用。</li>
            <li>如用户还要同时使用优惠券，则看用户是先选择优惠券还是先选择的红包，<b>先选择的先计算</b>。</li>
            <li>如您设置为“仅限原价订单可使用”，无论订单享受了“消费满减 / 满折”，还是用户使用了“优惠券”，均无法使用本红包。</li>
          </ol>
        </el-form-item>
        <el-form-item label="门店限制" prop="useAllBranch">
          <el-radio-group v-model="rewardForm.useAllBranch" @change="onChangeUseAllBranch">
            <el-radio :label="true">所有门店可用</el-radio>
            <el-radio :label="false">部分门店可用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="适用门店" prop="canUseBranch"  v-if="!rewardForm.useAllBranch">
          <el-table :data="rewardForm.canUseBranch" border stripe size="medium" style="width: 400px; line-height: 23px;" class="hui-mb-1">
            <el-table-column label="门店ID" prop="id"></el-table-column>
            <el-table-column label="门店名称" prop="label"></el-table-column>
          </el-table>
          <el-button @click="handleDialogVisibleBranch" type="primary" size="small" icon="el-icon-location" plain>设置可用门店</el-button>
        </el-form-item>
      </h-box>
      <h-box header="给用户打标签">
        <el-form-item label="领红包打标签" prop="userTagsGet">
          <hpro-select-tags :value.sync="rewardForm.userTagsGet" style="width: 400px;"></hpro-select-tags>
          <div class="hui-color-text-secondary hui-font-size-small">
            <span>给<b>领过</b>本红包的用户打标签，美味建议商户以标签管理参加过活动的用户。</span>
            <router-link to="/home/user/tags/list" target="_blank">新建标签</router-link>
          </div>
        </el-form-item>
        <el-form-item label="用红包打标签" prop="userTagsConsumed">
          <hpro-select-tags :value.sync="rewardForm.userTagsConsumed" style="width: 400px;"></hpro-select-tags>
          <div class="hui-color-text-secondary hui-font-size-small">
            <span>给<b>用过</b>本红包的用户打标签，美味建议商户以标签管理参加过活动的用户。</span>
            <router-link to="/home/user/tags/list" target="_blank">新建标签</router-link>
          </div>
        </el-form-item>
      </h-box>
      <h-box>
        <el-form-item label="" slot="footer" class="hui-mb-0">
          <el-button @click="handleSubmit('rewardForm')" :loading="loading" type="primary">{{ type === 'edit' ? '保存' : '创建' }}</el-button>
          <el-button @click="handleBack">返回</el-button>
        </el-form-item>
      </h-box>
    </el-form>

    <el-dialog title="请填写红包金额" :visible.sync="dialogVisibleEnum" width="500px">
      <el-form :model="enumForm" :rules="enumFormRoles" ref="enumForm" label-width="10em">
        <el-form-item label="红包金额" prop="_reduceCost">
          <el-input v-model.number="enumForm._reduceCost" placeholder="请输入" style="width: 240px;">
            <template slot="prepend">立减</template>
            <template slot="append">元</template>
          </el-input>
          <div class="hui-color-text-secondary hui-font-size-small">红包优惠最少 0.01 元，2 位小数以内</div>
        </el-form-item>
        <el-form-item label="红包起用金额" prop="_leastCost">
          <el-input v-model.number="enumForm._leastCost" placeholder="请输入" style="width: 240px;">
            <template slot="prepend">满</template>
            <template slot="append">元可用</template>
          </el-input>
          <div class="hui-color-text-secondary hui-font-size-small">起用金额填写 0 元即无门槛，限填写整数金额</div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="hui-text-right">
        <el-button @click="handleVisibleEnum">取 消</el-button>
        <el-button @click="handleSubmitEnum('enumForm')" type="primary">确 定</el-button>
      </div>
    </el-dialog>

    <hpro-dialog-branch :visible.sync="dialogVisibleBranch" :value.sync="rewardForm.canUseBranch"></hpro-dialog-branch>
  </div>
</template>

<script>
export default {
  data () {
    return {
      type: '',
      loading: false,
      dialogVisibleBranch: false,
      dialogVisibleEnum: false,
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() < Date.now()
        }
      },
      rewardForm: {
        luckyType: 'STATIC',
        reduceCost: undefined,
        _reduceCost: undefined,
        quantity: undefined,
        reduceCostMin: undefined,
        _reduceCostMin: undefined,
        reduceCostMax: undefined,
        _reduceCostMax: undefined,
        reduceCostTotal: undefined,
        _reduceCostTotal: undefined,
        reduceEnum: [],
        leastCost: 0,
        _leastCost: 0,
        title: '',
        dateInfoType: 'DATE_TYPE_FIX_TIME_RANGE', // 使用时间的类型
        _timeRange: [],
        beginTimeStamp: undefined, // 起用时间
        endTimeStamp: undefined, // 表示结束时间 ， 建议设置为截止日期的23:59:59过期。表示卡券统一过期时间，建议设置为截止日期的23:59:59过期
        fixedTerm: undefined, // type为DATE_TYPE_FIX_TERM时专用，表示自领取后多少天内有效，不支持填写0
        fixedBeginTerm: undefined, // 表示自领取后多少天开始生效，领取后当天生效填写0
        _endTimeStamp: undefined,
        useAllWeekly: true,
        canUseWeekly: [],
        useAllDaily: true,
        canUseDaily: [],
        originalFeeOnly: false,
        useAllBranch: true,
        canUseBranch: [],
        userTagsGet: [],
        userTagsConsumed: []
      },
      rewardFormRoles: {
        luckyType: [{
          required: true,
          message: '红包类型必选',
          trigger: 'change'
        }],
        _reduceCost: [{
          required: true,
          type: 'number',
          min: 0.01,
          message: '红包金额必填，最小 0.01',
          trigger: 'blur'
        }, {
          validator: this.$validateAmount,
          trigger: 'blur'
        }],
        _reduceCostMin: [{
          required: true,
          type: 'number',
          min: 0.01,
          message: '红包最小金额必填，2 位小数，最小 0.01',
          trigger: 'blur'
        }, {
          validator: this.$validateAmount,
          trigger: 'blur'
        }],
        _reduceCostMax: [{
          required: true,
          type: 'number',
          min: 0.01,
          message: '红包最大金额必填，2 位小数，最小 0.01',
          trigger: 'blur'
        }, {
          validator: this.$validateAmount,
          trigger: 'blur'
        }],
        _reduceCostTotal: [{
          required: true,
          type: 'number',
          message: '红包总金额上限必填',
          trigger: 'blur'
        }, {
          validator: this.$validateAmount,
          trigger: 'blur'
        }],
        reduceEnum: [{
          required: true,
          type: 'array',
          min: 1,
          message: '请填写随机金额种类',
          trigger: 'change'
        }],
        _leastCost: [{
          required: true,
          type: 'integer',
          message: '起用金额必填，限整数，最小 0',
          trigger: 'blur'
        }, {
          validator: this.$validateAmount,
          trigger: 'blur'
        }],
        quantity: [{
          required: true,
          type: 'integer',
          min: 1,
          max: 999999,
          message: '红包库存必填，1 - 999,999',
          trigger: 'blur'
        }],
        title: [{
          required: true,
          max: 9,
          message: '红包名称必填，最多 9 个字，建议简单直接',
          trigger: 'blur'
        }],
        dateInfoType: [{
          required: true,
          message: '红包有效期类型必选',
          trigger: 'change'
        }],
        _timeRange: [{
          required: true,
          type: 'array',
          len: 2,
          fields: {
            0: {
              required: true,
              type: 'integer',
              message: '红包有效期必填',
              trigger: 'change'
            },
            1: {
              required: true,
              type: 'integer',
              message: '红包有效期必填',
              trigger: 'change'
            }
          }
        }],
        fixedTerm: [{
          required: true,
          type: 'integer',
          min: 1,
          message: '必填，大于等于 1 天',
          trigger: 'blur'
        }],
        fixedBeginTerm: [{
          required: true,
          type: 'integer',
          min: 0,
          message: '必填，领取后当天生效填写 0，大于等于 0 天',
          trigger: 'blur'
        }],
        _endTimeStamp: [{
          type: 'integer',
          message: '日期格式错误',
          trigger: 'blur'
        }],
        useAllWeekly: [{
          required: true,
          type: 'boolean',
          message: '使用限制日期必选',
          trigger: 'change'
        }],
        canUseWeekly: [{
          required: true,
          type: 'array',
          min: 1,
          message: '可使用日期必填',
          trigger: 'change'
        }],
        useAllDaily: [{
          required: true,
          type: 'boolean',
          message: '使用时段限制必选',
          trigger: 'change'
        }],
        canUseDaily: [{
          required: true,
          type: 'array',
          min: 1,
          message: '可使用时段必选',
          trigger: 'change'
        }],
        originalFeeOnly: [{
          required: true,
          type: 'boolean',
          message: '订单限制必选',
          trigger: 'change'
        }],
        useAllBranch: [{
          required: true,
          type: 'boolean',
          message: '适用门店限制必选',
          trigger: 'change'
        }],
        canUseBranch: [{
          required: true,
          type: 'array',
          min: 1,
          message: '可使用门店必选',
          trigger: 'change'
        }],
        userTagsGet: [{
          type: 'array',
          message: '格式必须是array',
          trigger: 'change'
        }],
        userTagsConsumed: [{
          type: 'array',
          message: '格式必须是array',
          trigger: 'change'
        }]
      },
      enumForm: {
        _reduceCost: undefined,
        _leastCost: 0
      },
      enumFormRoles: {
        _reduceCost: [{
          required: true,
          type: 'number',
          min: 0.01,
          message: '红包金额必填，最小 0.01',
          trigger: 'blur'
        }, {
          validator: this.$validateAmount,
          trigger: 'blur'
        }],
        _leastCost: [{
          required: true,
          type: 'integer',
          message: '起用金额必填，限整数，最小 0',
          trigger: 'blur'
        }]
      }
    }
  },
  methods: {
    // 根据url判断类型
    setType () {
      let type = this.$route.query.type
      this.type = type
      if (type === 'edit') {
        this.initMockData()
      }
    },

    // 模拟数据
    initMockData () {},

    // 红包类型change事件
    onChangeLuckyType () {
      let luckyType = this.rewardForm.luckyType
      switch (luckyType) {
        case 'STATIC':
          this.rewardForm.reduceCostMin = undefined
          this.rewardForm._reduceCostMin = undefined
          this.reduceCostMax = undefined
          this._reduceCostMax = undefined
          this.reduceCostTotal = undefined
          this._reduceCostTotal = undefined
          this.reduceEnum = []
          break

        case 'RANDOM':
          this.rewardForm.reduceCost = undefined
          this.rewardForm._reduceCost = undefined
          this.rewardForm.quantity = undefined
          this.reduceEnum = []
          break

        case 'ENUM':
          this.rewardForm.reduceCost = undefined
          this.rewardForm._reduceCost = undefined
          this.reduceCostMax = undefined
          this._reduceCostMax = undefined
          this.reduceCostTotal = undefined
          this._reduceCostTotal = undefined
          this.rewardForm.leastCost = 0
          this.rewardForm._leastCost = 0
          break
      }
    },

    // 固定面额红包立减金额change
    onChangeReduceCost () {
      let _reduceCost = this.rewardForm._reduceCost
      if (_reduceCost !== undefined) {
        this.rewardForm.reduceCost = _reduceCost * 100
      }
    },

    // 随机面额红包最小金额change
    onChangeReduceCostMin () {
      let _reduceCostMin = this.rewardForm._reduceCostMin
      if (_reduceCostMin !== undefined) {
        this.rewardForm.reduceCostMin = _reduceCostMin * 100
      }
    },

    // 随机面额红包最大金额change
    onChangeReduceCostMax () {
      let _reduceCostMax = this.rewardForm._reduceCostMax
      if (_reduceCostMax !== undefined) {
        this.rewardForm.reduceCostMax = _reduceCostMax * 100
      }
    },

    // 随机面额红包总金额change
    onChangeReduceCostTotal () {
      let _reduceCostTotal = this.rewardForm._reduceCostTotal
      if (_reduceCostTotal !== undefined) {
        this.rewardForm.reduceCostTotal = _reduceCostTotal * 100
      }
    },

    // 红包起用金额change
    onChangeLeastCost () {
      let _leastCost = this.rewardForm._leastCost
      if (_leastCost !== undefined) {
        this.rewardForm.leastCost = _leastCost * 100
      }
    },

    // 添加红包枚举模态框显示隐藏
    handleVisibleEnum () {
      let visible = this.dialogVisibleEnum
      this.dialogVisibleEnum = !visible
      this.enumForm = {
        _reduceCost: undefined,
        _leastCost: 0
      }
    },

    // 添加红包枚举表单校验
    handleSubmitEnum (formName) {
      let enumForm = this.enumForm
      let tmp = {
        reduceCost: enumForm._reduceCost * 100,
        leastCost: enumForm._leastCost * 100
      }
      this.$formSubmit(formName).then(() => {
        this.rewardForm.reduceEnum.push(tmp)
        this.handleVisibleEnum()
      }).catch(() => {
        return false
      })
    },

    // 删除一个已经枚举的红包
    handleDeleteEnum (index, row) {
      let reduceEnum = this.rewardForm.reduceEnum
      reduceEnum.splice(index, 1)
      this.rewardForm.reduceCostEnum = reduceEnum
    },

    // 有效期类型变化change
    onChangeDateInfoType () {
      let dateInfoType = this.rewardForm.dateInfoType
      switch (dateInfoType) {
        case 'DATE_TYPE_FIX_TIME_RANGE':
          this.rewardForm.fixedTerm = undefined
          this.rewardForm.fixedBeginTerm = undefined
          break
        case 'DATE_TYPE_FIX_TERM':
          this.rewardForm._timeRange = []
          this.rewardForm.beginTimeStamp = undefined
          this.rewardForm.endTimeStamp = undefined
          break
      }
    },

    // 统一过期时间change事件
    onChangeEndTimeStamp (val) {
      let endTimeStamp = this.$moment(val).set({'hour': 23, 'minute': 59, 'second': 59}).format('X')
      this.rewardForm.endTimeStamp = endTimeStamp
    },

    // 设置可用星期为空
    onChangeCanUseWeekly () {
      if (this.rewardForm.useAllWeekly) {
        this.rewardForm.canUseWeekly = []
      }
    },

    // 设置可使用时段为空
    onChangeCanUseDaily () {
      if (this.rewardForm.useAllDaily) {
        this.rewardForm.canUseDaily = []
      }
    },

    // 可使用门店change
    onChangeUseAllBranch () {
      let useAllBranch = this.rewardForm.useAllBranch
      if (useAllBranch) {
        this.rewardForm.canUseBranch = []
      }
    },

    // 门店选择模态框打开关闭
    handleDialogVisibleBranch () {
      let dialogVisibleBranch = this.dialogVisibleBranch
      this.dialogVisibleBranch = !dialogVisibleBranch
    },

    // 返回
    handleBack () {
      this.$router.back()
    },

    // 表单校验
    handleSubmit (formName) {
      this.$formSubmit(formName).then(() => {
        console.log('表单校验成功，提交')
        this.$loading()
        this.loading = true
        setTimeout(() => {
          this.$message({
            message: '红包保存成功！',
            type: 'success'
          })
          this.handleBack()
          this.$loading().close()
        }, 1000)
      }).catch(() => {
        console.log('表单校验失败！')
        this.$message({
          message: '必要的信息没填写完整, 请检查!',
          type: 'warning'
        })
        this.loading = false
      })
    }
  },
  created () {}
}
</script>
